import json
import random
import os, sys
sys.path.append(os.path.dirname(os.path.realpath(os.getcwd())))
from IPython.display import display, clear_output
from random import randrange
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"]=25,25
import numpy as np
# Because Life, Universe and Everything!
random.seed(42)
def mdprint(text):
display({
'text/markdown': text,
'text/plain': text
}, raw=True)
# Dataset for Airborne Object Tracking Dataset
from core.dataset import Dataset
notebook_path = os.path.dirname(os.path.realpath("__file__"))
local_path = notebook_path + '/part1'
s3_path = 's3://airborne-obj-detection-challenge-training/part1/'
dataset = Dataset(local_path, s3_path)
2021-04-12 10:04:54.257 | INFO | core.dataset:load_gt:18 - Loading ground truth...
# You can add multi-part dataset as well, using below..
local_path = notebook_path + '/part2'
s3_path = 's3://airborne-obj-detection-challenge-training/part2/'
dataset.add(local_path, s3_path)
# You can add multi-part dataset as well, using below..
local_path = notebook_path + '/part3'
s3_path = 's3://airborne-obj-detection-challenge-training/part3/'
dataset.add(local_path, s3_path)
2021-04-12 10:05:11.886 | INFO | core.dataset:load_gt:18 - Loading ground truth... 2021-04-12 10:05:31.329 | INFO | core.dataset:load_gt:18 - Loading ground truth...
all_flight_ids = dataset.get_flight_ids()
lucky_flight_id = random.choice(all_flight_ids)
lucky_flight_id = '7a1f085ad3834f53ae8e19cbbfe1bd36'
lucky_flight = dataset.get_flight_by_id(lucky_flight_id)
mdprint("## 🔮Lucky draw tells us to continue with: `%s`" % lucky_flight_id)
mdprint("### Let's know our flight a bit more! 🔎")
print(lucky_flight)
mdprint("This flight has **%s frames** and total **%s airborne objects**." % (lucky_flight.num_frames, lucky_flight.num_airborne_objs))
mdprint("List of Airborne Objects: ")
for airborne_obj in lucky_flight.get_airborne_objects():
mdprint("- %s " % airborne_obj)
7a1f085ad3834f53ae8e19cbbfe1bd36¶Flight#7a1f085ad3834f53ae8e19cbbfe1bd36(num_frames=1199, num_airborne_objs=14)
This flight has 1199 frames and total 14 airborne objects.
List of Airborne Objects:
Please note, downloading image for each frame would be slower, so when using for training downloading whole dataset is preferred.
You can download full dataset using following command in your directory:
aws s3 sync s3://airborne-obj-detection-challenge-training/part1 part1/ --no-sign-request
aws s3 sync s3://airborne-obj-detection-challenge-training/part1 part2/ --no-sign-request
aws s3 sync s3://airborne-obj-detection-challenge-training/part1 part3/ --no-sign-request
You can download individual flight using below command:
aws s3 sync s3://airborne-obj-detection-challenge-training/part1/Images/{{flight_id}} part1/Images/{{flight_id}} --no-sign-request
or:
lucky_flight.download()
image = lucky_flight.get_frame(randrange(lucky_flight.num_frames)).image()
display(image)
You can try out whole video as well if you have dataset downloaded
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"]=25,25
fig = plt.figure()
for i in range(1, 10):
ax = fig.add_subplot(3, 3, i)
ax.imshow(lucky_flight.get_frame(randrange(lucky_flight.num_frames)).image(type='cv2'))
plt.show()
airborne_objects = lucky_flight.detected_objects
frames = lucky_flight.frames
rows = len(airborne_objects.keys())
detected = {}
distance = {}
for frame_id in lucky_flight.frames:
f = lucky_flight.get_frame(frame_id)
for obj in airborne_objects:
if obj not in detected:
detected[obj] = []
distance[obj] = []
if obj in f.detected_objects:
detected[obj].append(True)
distance[obj].append(f.detected_object_locations[obj].range_distance_m)
else:
detected[obj].append(False)
if not airborne_objects[obj].planned:
distance[obj].append(float("NaN"))
else:
distance[obj].append(0)
i = 0
f = plt.figure(figsize=(25, 25), dpi=80)
f, axes = plt.subplots(nrows = rows, ncols = 2, squeeze=False)
for obj in detected:
axes[i][0].scatter(range(len(distance[obj])), distance[obj])
axes[i][0].set_xlabel('Frame')
axes[i][0].set_ylabel('Distance')
axes[i][0].set_title(obj)
if not airborne_objects[obj].planned:
plt.text(0.3, 0.2, "Unplanned objects\ndon't have distance",
fontsize=20, transform=axes[i][0].transAxes, color="grey")
axes[i][1].scatter(range(len(detected[obj])), detected[obj])
axes[i][1].set_xlabel('Frame')
axes[i][1].set_ylabel('Present')
axes[i][1].set_title(obj)
i += 1
# for obj in detected:
# dt = random.choice(airborne_objects[obj].location)
# img = dt.frame.image_annotated()
# axes[[i, i+1]][1].imshow(img)
display(plt.show())
<Figure size 2000x2000 with 0 Axes>
None
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"]=25,25
import time
# Let's get one of the "planned" object in this video
airborne_objects = lucky_flight.detected_objects
obj_of_interest = None
for obj in airborne_objects:
if airborne_objects[obj].planned:
obj_of_interest = airborne_objects[obj]
break
images = []
fig = plt.figure()
for i in range(1, 7, 2):
frame = obj_of_interest.location[randrange(obj_of_interest.num_frames)].frame
ax = fig.add_subplot(3, 2, i)
ax.imshow(frame.image(type='cv2'))
ax = fig.add_subplot(3, 2, i + 1)
ax.imshow(frame.image_annotated())
plt.show()
flight_path = lucky_flight.generate_video(speed_x=5)
2021-04-12 10:07:16.824 | INFO | core.flight:generate_video:112 - Generating video...
from IPython.display import Video
Video(flight_path, embed=True, width=786)